/** 
 * @description: TODO (描述这个文件的作用) 
 * Project Name:creditcat-bird, File Name:KakEncodeUtil.java 
 * Copyright (c) 2017, 张新功,Inc.All Rights Reserved. 
*/
package com.vcredit.bird.util;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;

import com.vcredit.creditcat.util.Constants;
import com.vcredit.creditcat.util.RSAUtil;

/** 
 * @description: TODO(描述这个类的作用) 
 * @author 张新功 
 * @date 2017年7月6日 
*/
public class KakEncodeUtil {

  public static String encodeJsonParam(String jsonParam) throws UnsupportedEncodingException,
      Exception {
    // 加密
    String requestContentBase64 =
        Base64.encodeBase64String(RSAUtil.encryptByPrivateKey(jsonParam.getBytes("utf-8"),
            Constants.KAK_PRIVATE_KEY));
    return requestContentBase64;
  }

  public static String decodeJsonParam(String respJson) throws Exception {
    String result = "";
    // 解密
    byte[] res = RSAUtil.decryptBASE64(respJson);
    result = new String(RSAUtil.decryptByPublicKey(res, Constants.KAK_PUBLIC_KEY));
    return result;
  }
}
